//
//  IGADView.m
//  jingdongfang
//
//  Created by MTiMac01 on 2017/11/9.
//  Copyright © 2017年 LJL. All rights reserved.
//

#import "IGADView.h"
#import "XiangQingViewController.h"
#import "IntroViewController.h"
#import "ZTXQViewController.h"
#import "BaseWebViewController.h"
#import "GoodsDetailVC.h"
@interface IGADView ()
@property(strong,nonatomic) UIButton        *closeBtn;
@property(retain,nonatomic) UIImageView     *adImageView;
@end

@implementation IGADView

- (instancetype)initWithModel:(IGPopPicture *)model
{
    if (self = [super init])
    {
        self.frame = CGRectMake(0, 0, KSCREENWIDTH, KSCREENHEIGHT);
        self.backgroundColor = [UIColor clearColor];
        UIView *masView = [UIView new];
        masView.frame = self.bounds;
        masView.backgroundColor = [UIColor colorWithHex:@"#000000"];
        masView.alpha = 0.6;
        [self addSubview:masView];
        
        self.adImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, KSCREENWIDTH - 60, (KSCREENWIDTH - 60) * 40 / 29)];
        _adImageView.userInteractionEnabled = YES;
        [_adImageView sd_setImageWithURL:[NSURL URLWithString:model.image]];
        _adImageView.center = CGPointMake(KSCREENWIDTH/2, KSCREENHEIGHT/2);
        @KWeakObj(self)
        [_adImageView setTapActionWithBlock:^{
            //1-作品 2-艺术家 3-专题 4-活动 5-商品 6-web
            NSString *linkType = model.linkType;
            NSString *linkId = model.linkId;
            if ([linkType isEqualToString:@"1"])
            {
                XiangQingViewController *vc = [[XiangQingViewController alloc] init];
                vc.p_id = linkId;
                vc.isRoot = YES;
                [UIViewController ig_pushViewController:vc animated:YES];
            }
            else if ([linkType isEqualToString:@"2"])
            {
                IntroViewController *vc = [[IntroViewController alloc] init];
                vc.u_id = linkId;
                [UIViewController ig_pushViewController:vc animated:YES];
            }
            else if ([linkType isEqualToString:@"3"] || [linkType isEqualToString:@"4"])
            {
                ZTXQViewController *vc = [[ZTXQViewController alloc] init];
                vc.s_id = linkId;
                [UIViewController ig_pushViewController:vc animated:YES];
            }
            else if ([linkType isEqualToString:@"5"])
            {
                GoodsDetailVC *vc = [[GoodsDetailVC alloc] init];
                vc.goodsId = linkId;
                [UIViewController ig_pushViewController:vc animated:YES];
            }
            else if ([linkType isEqualToString:@"6"])
            {
                BaseWebViewController *vc = [[BaseWebViewController alloc] initWithUrl:linkId];
                [UIViewController ig_pushViewController:vc animated:YES];
            }
            [selfWeak closeBtnClickEventHandle];
        }];
        _adImageView.clipsToBounds = YES;
        [self addSubview:_adImageView];
        
        self.closeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        _closeBtn.frame = CGRectMake((KSCREENWIDTH - 30) / 2, 50, 30, 30);
        [_closeBtn setBackgroundImage:[UIImage imageNamed:@"home_close"] forState:normal];
        [_closeBtn addTarget:self action:@selector(closeBtnClickEventHandle) forControlEvents:UIControlEventTouchUpInside];
        [masView addSubview:_closeBtn];
    }
    return self;
}


- (void)closeBtnClickEventHandle
{
    [self removeFromSuperview];
}

- (void)showInView:(UIView *)view
{
    [view addSubview:self];
}

@end
